package cn.xo68.metadata.mapper;


import cn.xo68.metadata.entity.MetadataProject;
import org.apache.ibatis.annotations.*;
import java.util.List;

/** 
 * MetadataProject mybatis mapper
 * @author wuyy(16349023@qq.com)
 * @date 2020年03月12日 11:44:16
 *
 */
public interface MetadataProjectMapper {


	
	@Select("SELECT * FROM metadata_project WHERE project_id = #{projectId}")
    @Results(value = { 
    @Result(id = true, column = "project_id", property = "projectId"),
        @Result(column = "department_code", property = "departmentCode"),
        @Result(column = "parent_project_id", property = "parentProjectId"),
        @Result(column = "project_name", property = "projectName"),
        @Result(column = "project_code", property = "projectCode"),
        @Result(column = "database_type", property = "databaseType"),
        @Result(column = "database_version", property = "databaseVersion"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
    })
    MetadataProject find(@Param("projectId") Integer projectId);
	
	@Select("SELECT * FROM metadata_project")
    @Results(value = { 
    @Result(id = true, column = "project_id", property = "projectId"),
        @Result(column = "department_code", property = "departmentCode"),
        @Result(column = "parent_project_id", property = "parentProjectId"),
        @Result(column = "project_name", property = "projectName"),
        @Result(column = "project_code", property = "projectCode"),
        @Result(column = "database_type", property = "databaseType"),
        @Result(column = "database_version", property = "databaseVersion"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
    })
    List<MetadataProject> list();
	
	@Insert("insert into metadata_project (project_id ,department_code ,parent_project_id ,project_name ,project_code ,database_type ,database_version ,create_time ,update_time ) values (#{projectId} , #{departmentCode} , #{parentProjectId} , #{projectName} , #{projectCode} , #{databaseType} , #{databaseVersion} , #{createTime} , #{updateTime}  )")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="projectId", before=false, resultType=Integer.class)
    @Options(useGeneratedKeys = true, keyProperty = "projectId")
    int insert(MetadataProject metadataProject);
	
	@Update({"update metadata_project set",
      " department_code=#{departmentCode}, parent_project_id=#{parentProjectId}, project_name=#{projectName}, project_code=#{projectCode}, database_type=#{databaseType}, database_version=#{databaseVersion}, create_time=#{createTime}, update_time=#{updateTime} ",
      "where project_id = #{projectId}"
    })
    int update(MetadataProject metadataProject);

	@Delete("delete FROM metadata_project WHERE project_id = #{projectId}")
	int delete(@Param("projectId") Integer projectId);
}